package net.hn.hnms.biz.dust.controller.feign;

import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.api.safety.monitor.model.BaseSensorCoordDto;
import net.hn.hnms.biz.dust.domain.DwdFcfzBaseSensorinfoEntity;
import net.hn.hnms.biz.dust.repository.FcfzBaseRepository;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 远程调用粉尘防止系统数据
 */
//@ApiIgnore
@RestController
@RequestMapping("/remoteFcfz")
@Validated
@RequiredArgsConstructor
public class RemoteFzfzController {
    @Resource
    private FcfzBaseRepository fcfzBaseRepository;

    /**
     * 获取粉尘BaseSensorTable表所有信息
     */
    @GetMapping("getBaseSensorTableAllList")
    public List<BaseSensorCoordDto> getBaseSensorTableAllList(String mineCode, String companyCode){
//        List<DwdFcfzBaseSensorinfoEntity> dwdFcfzBaseSensorinfoEntities = fcfzBaseRepository.findAll();
        List<DwdFcfzBaseSensorinfoEntity> dwdFcfzBaseSensorinfoEntities = fcfzBaseRepository.findByMineCode(mineCode);
        if (dwdFcfzBaseSensorinfoEntities.isEmpty()) {
            return new ArrayList<>();
        }
        List<BaseSensorCoordDto> baseSensorInfoNowPoList = dwdFcfzBaseSensorinfoEntities.stream().map(t -> {
            BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
            //传感器编码 分站编码
            baseSensorCoordDto.setPointCode(t.getPointCode());
            //传感器名称 分站名称
            baseSensorCoordDto.setLocation(t.getPointName());
            //传感器类型编码
            baseSensorCoordDto.setSensorTypeCode(t.getPointTypeCode());
            //传感器类型名称
            baseSensorCoordDto.setSensorTypeName(t.getPointTypeName());
            //x
            baseSensorCoordDto.setXCoordinate(t.getxCoordinate());
            //y
            baseSensorCoordDto.setYCoordinate(t.getyCoordinate());
            //z
            baseSensorCoordDto.setZCoordinate(t.getzCoordinate());

            return baseSensorCoordDto;
        }).collect(Collectors.toList());

        return baseSensorInfoNowPoList;
    }
}